Ext.ns('ATS.pipeline');

(function(){
			/*This Method is used to create dynamic column model*/
	
			ATS.pipeline.createCM=function(dataIndexs,columnHeader){
									var colModel=new Ext.grid.ColumnModel({columns:[]});
									
									for(var i=0;i<columnHeader.length;i++)
									{
										
										colModel.columns[i]={
												id:i,
												header:columnHeader[i],
												sortable:true,
												dataIndex:dataIndexs[i],
												width:columnHeader[i].length*12,
												align:'center'//,
												//hidden:false
												                 };
									 }
									
									return colModel;
							},
				
							/*This Method is used to create dynamic store model*/
							
			ATS.pipeline.createStore=function (storeid,fieldsArray,url){
								var store=new Ext.data.JsonStore({
									id:storeid,
									root:'data',
									autoLoad:true,
									fields:fieldsArray,
									proxy : new Ext.data.HttpProxy({
										method: "GET",
										url : url
										
									})

								});
							  return store;	
							},
			ATS.pipeline.createGrid=function(gridid,datastore,cmodel){
								var grid= new Ext.grid.GridPanel({
									
									id 			:gridid,
									height	: 250,
									store 		: datastore,
									colModel 	: cmodel,		
									stripeRows	: true,
									enableRowBody : true,
									scrollable:true,
									enableColumnResize:true,
									defaults:{align:'center'},
									sm: new Ext.grid.RowSelectionModel({singleSelect : true}),
							        listeners: {
							        			  viewready: function(g) {
							              								 g.getSelectionModel().selectRow(0);
							          									 }
						     	 				}
									
								});
								return grid;
							},
			ATS.pipeline.createComboStore=function(storedid,actionurl,method){
								actionurl=actionurl+"?operation="+method;
								var comboboxStore = new Ext.data.JsonStore({
									id:storedid,
									root          : 'data',
									fields     : [
										{
									    name    : 'caption',
									    mapping : 'caption'
										},
										{
									    name    : 'value',
									    mapping : 'value'
										}
										,
										{
										    name    : 'intid',
										    mapping : 'intid'
											},
											{
										    name    : 'intValue',
										    mapping : 'intValue'
											}		
									],
									proxy : new Ext.data.HttpProxy({
										method: 'GET',
										url : actionurl
										
									})
								}); 
									return comboboxStore;
								
							},
	ATS.pipeline.performAction=function(path,methodtype){
								    if(methodtype=='Out'){
							    	   			path=path+'&operation='+methodtype;
							    	   }
							       	else{
							       				path=path+'?operation='+methodtype;
							       		}
							       
							       
							        Ext.Ajax.request({
							        	   url: path,
							        	   method: 'POST',
							        	  
							        	   success: function(results) 
							        	   			{ 
							   						if(results.responseText!=null){
							   	   						if(methodtype=='save')
							   	   						// reloadCandidateHistory(results.responseText);
							   	   					
							       					 	if(methodtype=='Next' || methodtype=='Out' || methodtype=='Hold')
							       					 	{
							       					 		//reloadTree();
							       					 	   // moveCandidateDetails();
							           					 }
							   						}
							   	   	
							   	   					},
							        	   failure: function() { alert ("Failure");}
							        	   
							        	});
								
							};	

})();


/*Requirement Tab start here */

PipeLineRequirement=Ext.extend(Object,{
	columnText:function(){return ['Serial#','JR#','Department','Title','Prescreen','Screen','Phone','Direct','Offer Init','Offer Final','BVT','BVR','VISA','Arrival','Out','Total','Priority'];},
	columnData:function(){return ['jobRequestid','jobRequestno','departmentName','title','prescreen','cvreview','phoneInterview','directInterview','offerInit','offerFinal','bvt','bvr','visa','arrival','out','total','priority'];},
	gridid:function(){return 'requirementGridid';},
	colmodel:function(){
						var colm=ATS.pipeline.createCM(this.columnData(),this.columnText());
				        colm.columns[0].hidden=true;
				       
				        var action=new Ext.grid.ActionColumn(items=[2]);
				         action.header="Actions";
				         action.items[0].icon="images/forward.gif";
				         action.items[0].tooltip="Pipeline";
				         
				         colm.columns[this.columnText().length]=action;
				        return colm;
					},
	requirementStore:function(){return ATS.pipeline.createStore('requirementStore',this.columnData(),'pipelines/fillRequiremenGrid');},
	requirementGrid:function(){return ATS.pipeline.createGrid(this.gridid(),this.requirementStore(),this.colmodel());},
	reloadGrid:function(deptid,priorityid){
									var grid=Ext.getCmp(this.gridid());
									grid.getStore().reload({
								    params:{
											deptid : deptid.value,
											priorityid : priorityid.value
											}
										});		
		}

});

ATS.pipeline.PipeLineRequirement=new PipeLineRequirement();

ATS.pipeline.RequirementHeader=Ext.extend(Ext.Panel,{
	
	autoWidth:'auto',
	id:'toppanel',
    height: 50,
    frame: true,
    labelWidth: 75,
    initComponent:function(){
	Ext.apply(this,{
		items:[
		       	{
		       		xtype:'panel',
		       		id:'requirenetHeader',
		       		layout:'form',
		       		items:[
		       		      {
		       		        xtype : 'compositefield',
		       		        id:'requirenetHeadercomp',
		       		        fieldLabel	: '<b>Department</b>',
		       		        width:360,
		       		        border :0,
		       		        items : [
		       		                 {
		       		                	xtype		:'combo',
										name		:'departmentName',
										id			:'departmentid',
										store: ATS.pipeline.createComboStore('rdeptstore','pipelines/pipelineReqCombo','departmentName'),
										displayField : 'caption',
										valueField : 'value',
										triggerAction : 'all',
										typeAhead: true,
										width : 120,
										emptyText: 'Select Departments',
										selectOnFocus:true
		       		                 },
		       		              {xtype:'displayfield',value:'<b>Priority</b>'},
		       		                 {
		       		                	xtype:'combo',
		       		                	
									    name:'priority',
										id:'priorityid',
										store: ATS.pipeline.createComboStore('rprioritystore','pipelines/pipelineReqCombo','priority'),
										displayField : 'caption',
										valueField : 'value',
										triggerAction : 'all',
										typeAhead: true,
										width : 120,
										emptyText: 'Select Priority',
										selectOnFocus:true
		       		                 },
		       		                 {
		       		                	 xtype	: 'button',
		       		                	 text	: 'Show All',
		       		                	 handler :function(){
		       		                	 				var dept=Ext.getCmp('departmentid');
		       		                	 				var priority=Ext.getCmp('priorityid');
		       		                	 			    ATS.pipeline.PipeLineRequirement.reloadGrid(dept,priority);
		       		                	 					
		       		                 }
		       		                	 
		       		                 } 
		       		                ]
		       		       	}
		       		      
		       		       ]
		       	}
		       		       
		       ]
	});

	ATS.pipeline.RequirementHeader.superclass.initComponent.call(this);
	
}

});

Ext.reg('requirementHeader',ATS.pipeline.RequirementHeader);

/* Requirement Tab end here */

/*Pipe line Phase start here */
/*
PipelinePhaseGrid=Ext.extend(Object,{
	columnText:function(){return ['applicationId','jrid','jrno','candidateID','Candidate Name','Phone','Type','Typeid','Agency','P','D','N','Alert','callCounter','directcounter'];},
	columnData:function(){return ['applicationId','jrid','jrno','candidateid','candidateName','phone','type','typeid','agencyName','p','d','n','callCounter','directcounter'];},
	gridid:function(){return 'phasegridid';},
	colmodel:function(){ 
							var colm=ATS.pipeline.createCM(this.columnData(),this.columnText());
							//alert(colm.findColumnIndex('applicationId'));
									colm.setHidden(colm.findColumnIndex('applicationId'),true);
									colm.setHidden(colm.findColumnIndex('jrid'),true);
									colm.setHidden(colm.findColumnIndex('jrno'),true);
									
									return colm;
							},
	phasegridStore:function(){return ATS.pipeline.createStore('phasegridStore',this.columnData(),'pipelines/candidateInPhase');},
	phaseGrid:function(){return ATS.pipeline.createGrid(this.gridid(),this.phasegridStore(),this.colmodel());}
						
});

ATS.pipeline.PipelinePhaseGrid=new PipelinePhaseGrid();*/
/* Pipe line phase end here */



